// pages/courseOrder/detail.js
Page({
  data: {
    order: {
      orderNo: 'EDU20230715123456',
      status: 'paid',
      createTime: '2023-07-15 14:30:22',
      payMethod: '微信支付',
      amount: 299.00,
      expireDate: '2024-07-15',
      studentInfo: {
        name: '王同学',
        phone: '138****1234'
      },
      course: {
        coverUrl: '/images/course-cover.jpg',
        title: '心理咨询师精讲课程',
        subtitle: '构建内心界限,活出力量与自信',
        lessonCount: 30,
        studentCount: 1258
      }
    },
    statusText: {
      unpaid: '待支付',
      paid: '已支付',
      cancelled: '已取消',
      expired: '已过期'
    },
    statusIcon: {
      unpaid: 'info',
      paid: 'success',
      cancelled: 'warn',
      expired: 'cancel'
    },
    statusBg: {
      unpaid: '#FF9500, #FFBE00',
      paid: '#09BB07, #2dbb2a',
      cancelled: '#888, #999',
      expired: '#888, #999'
    }
  },

  onLoad(options) {
    // 实际开发中应从服务器获取订单详情
    // this.loadOrderDetail(options.orderNo);
  },

  handlePay() {
    wx.navigateTo({
      url: `/pages/payment/index?orderNo=${this.data.order.orderNo}&amount=${this.data.order.amount}`
    });
  },

  handleCancel() {
    wx.showModal({
      title: '取消订单',
      content: '确定要取消此课程订单吗？',
      success: (res) => {
        if (res.confirm) {
          // 调用取消订单接口
          wx.showToast({
            title: '订单已取消',
            icon: 'success'
          });
          this.setData({
            'order.status': 'cancelled'
          });
        }
      }
    });
  },

  handleStudy() {
    wx.navigateTo({
      url: `/pages/course/study?id=${this.data.order.course.id}`
    });
  },

  onShareAppMessage() {
    return {
      title: `我在学习「${this.data.order.course.title}」`,
      path: `/pages/course/detail?id=${this.data.order.course.id}`
    };
  }
});